package videoconferencia

import grails.test.*

class MaterialServiceTests extends GrailsUnitTestCase {
    protected void setUp() {
        super.setUp()
    }

    protected void tearDown() {
        super.tearDown()
    }
	
	void testExistsFalse() {
		//mock Domain class
		mockDomain(Material)
		
		Material m1 = new Material(nome:"Datashow")
		m1.save()
		Material m2 = new Material(nome:"PenDrive")
		m2.save()
		
		MaterialService service = new MaterialService()
		assertEquals service.materialExists("Notebook"), null
	}

    void testExistsTrue() {
		//mock Domain class
		mockDomain(Material)
		
		Material m1 = new Material(nome:"Datashow")
		m1.save()
		Material m2 = new Material(nome:"PenDrive")
		m2.save()
		
		MaterialService service = new MaterialService()
		assertEquals service.materialExists("PenDrive").id, m2.id
    }
	
	void testListAll() {
		//mock Domain class
		mockDomain(Material)
		
		MaterialService service = new MaterialService()
		service.materialCreate("Notebook")
		service.materialCreate("Data Show")
		service.materialCreate("Pendrive")
		
		def lista = service.materialListAll()
		
		assertEquals lista.get(2).nome, "Pendrive"
		assertEquals lista.get(2).id, 3
	}
	
	void testCreateFalse() {
		//mock Domain class
		mockDomain(Material)
		
		Material m1 = new Material(nome:"Datashow")
		m1.save()
		
		MaterialService service = new MaterialService()
		Material encontrado = service.materialCreate("Datashow")
		
		assertEquals encontrado, null
	}
	
	void testCreateTrue() {
		//mock Domain class
		mockDomain(Material)
		
		MaterialService service = new MaterialService()
		service.materialCreate("Datashow")
		service.materialCreate("Notebook")
		
		assertEquals service.materialCreate("DataShow").id, 3
	}
	
	void testUpdateFalse() {
		mockDomain(Material)
		
		MaterialService service = new MaterialService()
		service.materialCreate("Datashow")
		service.materialCreate("Notebook")
		
		Material encontrado = service.materialUpdate(service.materialExists("Pendrive"), "Data Show")
		
		assertEquals encontrado, null
	}
	
	void testUpdateTrue() {
		mockDomain(Material)
		
		MaterialService service = new MaterialService()
		service.materialCreate("Datashow")
		service.materialCreate("Notebook")
		
		Material encontrado = service.materialUpdate(service.materialFind(1), "Data Show")
		
		assertEquals "Data Show", encontrado.nome
	}
	
	void testDelete() {
		mockDomain(Material)
		
		MaterialService service = new MaterialService()
		service.materialCreate("Datashow")
		service.materialCreate("Notebook")
		service.materialCreate("Pendrive")
		
		assertEquals service.materialDelete(service.materialFind(3)), true
		assertEquals service.materialExists("Pendrive"), null
	}
}
